from PyQt4.QtGui import QDialog
from PyQt4.QtGui import QGridLayout, QHBoxLayout, QVBoxLayout

from PyQt4.QtCore import SIGNAL

from views.widgets.pushButton import PushButton
from views.widgets.Label import Label

class PlayerWidget(QGridLayout):
    def __init__(self, parent=None):
        super(PlayerWidget, self).__init__(parent)
        # data
        self.username = ''
        self.score = 100
        self.success = 0
        self.failure = 0
        self.ready = False
        # Labels
        self.usernameLabel = Label()
        self.scoreLabel = Label()
        self.successLabel = Label()
        self.failureLabel = Label()
        self.readyLabel = Label()
        # Layout
        self.addWidget(self.usernameLabel, 0, 0)
        self.addWidget(self.scoreLabel, 0, 1)
        self.addWidget(self.successLabel, 1, 0)
        self.addWidget(self.failureLabel, 1, 1)
        self.addWidget(self.readyLabel, 0, 2)

    def setNickName(self, username):
        self.username = username
        self.usernameLabel.setText('Name:' + username)

    def setScore(self, score):
        self.score = score
        self.scoreLabel.setText('Score:' + str(score))

    def setHistory(self, success, failure):
        self.success = success
        self.failure = failure
        self.successLabel.setText('Success:' + str(success))
        self.failureLabel.setText("Failure:" + str(failure))

    def setReady(self, ready):
        self.ready = ready
        if ready:
            self.readyLabel.setText('Ready')
        else:
            self.readyLabel.setText('')


class PartnerView(QDialog):
    def __init__(self, parent=None):
        super(PartnerView, self).__init__(parent)
        self.setWindowTitle('Find Partner')
        # data
        self.username = ''
        self.success = 0
        self.failure = 0
        self.score = 100
        self.ready = False
        # widget
        self.partnerWidget = PlayerWidget()
        self.selfWidget = PlayerWidget()
        self.readyButton = PushButton('Ready')
        self.changeButton = PushButton('Change')
        self.returnButton = PushButton('Return')
        # Layout
        self.buttonBox = QHBoxLayout()
        self.buttonBox.addWidget(self.readyButton)
        self.buttonBox.addWidget(self.changeButton)
        self.buttonBox.addWidget(self.returnButton)
        self.mainLayout = QVBoxLayout()
        self.mainLayout.addLayout(self.partnerWidget)
        self.mainLayout.addLayout(self.selfWidget)
        self.mainLayout.addLayout(self.buttonBox)
        self.setLayout(self.mainLayout)


    def setSelfData(self, username, success, failure, score):
        self.username = username
        self.success = success
        self.failure = failure
        self.score = score
        self.selfWidget.setNickName(username)
        self.selfWidget.setHistory(success, failure)
        self.selfWidget.setScore(score)
        self.selfWidget.setReady(False)

    def setPartnerData(self, username, success, failure, score, ready):
        self.partnerWidget.setNickName(username)
        self.partnerWidget.setHistory(success, failure)
        self.partnerWidget.setScore(score)
        self.partnerWidget.setReady(ready)




